<template>
  <div class="ke-banner">
    <el-carousel :interval="interval" type="card" :height="height" :arrow="arrow">
      <el-carousel-item v-for="(img, index) in imgList" :key="index">
        <img :src="img.url" :width="width" />
      </el-carousel-item>
    </el-carousel>
    <div class="login" v-show="!userInfo">
      <div class="title">跟进您的学习进度</div>
      <div class="icon">
        <img src="../../assets/images/icon-tologin.png" alt />
      </div>
      <div class="btn" @click="handleToLoginPage">
        <el-button type="primary">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ke-banner-swiper',
  props: {
    imgList: {
      type: Array,
      default: () => [
        {
          url: require('../../assets/images/banners/banner1.jpg')
        },
        {
          url: require('../../assets/images/banners/banner2.jpg')
        },
        {
          url: require('../../assets/images/banners/banner3.jpg')
        },
        {
          url: require('../../assets/images/banners/banner4.jpg')
        },
        {
          url: require('../../assets/images/banners/banner5.jpg')
        },
        {
          url: require('../../assets/images/banners/banner6.jpg')
        }
      ]
    },
    arrow: {
      type: String,
      default: 'never'
    },
    height: {
      type: String,
      default: '300px'
    },
    width: {
      type: String,
      default: '768'
    },
    interval: {
      type: Number,
      default: 3000
    }
  },
  computed: {
    userInfo() {
      return localStorage.getItem('ke_id')
    }
  },
  methods: {
    handleToLoginPage() {
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="stylus" scoped>
.ke-banner {
  position: relative;
  min-width: 1200px;
  overflow: hidden;

  /deep/.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  /deep/.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }

  .login {
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    top: 25px;
    right: 50px;
    width: 220px;
    height: 250px;
    background-color: #ffffff;
    box-shadow: 0 1px 10px 3px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    z-index: -1;
    overflow: hidden;
    padding-top: 21px;
    align-items: center;

    .title {
      font-size: 16px;
      color: #999999;
    }

    .icon {
      position: relative;
      width: 170px;
      height: 130px;
      overflow: hidden;
      margin-top: 10px;

      img {
        position: absolute;
        top: -380px;
        right: -15px;
      }
    }

    .btn {
      width: 200px;

      /deep/.el-button {
        width: 100%;
      }
    }
  }
}
</style>
